<!DOCTYPE html>
<html>
<head>
<title>“花”点心思商城后台商品添加</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="../css/common.css">
<link rel="stylesheet" href="../css/main.css">
<link rel="shortcut icon" href="../../images/yc.png" type="image/x-icon" />
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/showpic.js"></script>
<script type="text/javascript" src="../js/ajaxfileupload.js"></script>
<script src="../../ckeditor/ckeditor.js"></script>
<script type="text/javascript">

</script>
</head>
<body>
<div id="forms" class="mt10">
	<div class="box">
		<div class="box_border">
			<div class="box_top">
				<b class="pl15">添加商品信息</b>
			</div>
			<div class="box_center">
				<form action="" class="jqtransform" id="addGoodsForm">
					<table class="form_table pt15 pb15" width="100%" border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td class="td_right">商品类型：</td>
							<td>
								<select class="select" name="tid" id="goodsType">
								
								</select>
							</td>
							<td class="td_right">商品名称：</td>
							<td>
								<input type="text" id="gname" name="title" class="input-text lh30" size="40" placeholder="请输入商品名称">
							</td>
							<td class="td_right">商品单价：</td>
							<td>
								<input type="number" id="price" name="price" class="input-text lh30" size="40" placeholder="单价"/>
							</td>
						</tr>
						<tr>
							<td class="td_right">商品库存：</td>
							<td>
								<input type="number" id="balance" name="balance" class="input-text lh30" size="40"  placeholder="库存"/>
							</td>
							<td class="td_right">商品单位：</td>
							<td>
								<input type="text" id="unit" name="unit" class="input-text lh30" size="40" placeholder="单位"/>
							</td>
							<td class="td_right">保质期：</td>
							<td>
								<input type="text" id="qperied" name="qperied" class="input-text lh30" size="40"  placeholder="保质期"/>
							</td>
						</tr>
						<tr>
							<td class="td_right">商品净重：</td>
							<td>
								<input type="text" id="weight" name="weight" class="input-text lh30" size="40" placeholder="净重" >
							</td>
							<td class="td_right">商品图片：</td>
							<td>
								<input type="file" id="pic" name="pic" class="input-text lh30" size="40" multiple="multiple" onchange="setImagePreviews(this,'showPics')">
							</td>
							<td></td>
							<td></td>
						</tr>
						<tr>
							<td>&nbsp;</td>
							<td colspan="5" align="center">
								<div id="showPics">
								
								</div>
							</td>
						</tr>
						<tr>
							<td class="td_right">商品简介：</td>
							<td colspan="5">
								 <textarea name="intro" id="intro" rows="3" cols="100"></textarea>
							</td>
						</tr>
						<tr>
							<td class="td_right">商品描述：</td>
							<td colspan="5">
								 <textarea name="editor1" id="editor1" rows="10" cols="80"></textarea>
							</td>
						</tr>
						<tr>
							<td colspan="4" align="center">
								<input type="button" name="button" class="btn btn82 btn_save2" onclick="addGoodsInfo()" value="添加">
								<input type="reset" name="button" class="btn btn82 btn_res" value="重置">
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
CKEDITOR.replace( 'editor1' );

function addGoodsInfo() {
	var tno = $.trim($("#goodsType").val());
	var gname = $.trim($("#gname").val());
	var price = $.trim($("#price").val());
	var balance = $.trim($("#balance").val());
	var unit = $.trim($("#unit").val());
	var qperied = $.trim($("#qperied").val());
	var weight = $.trim($("#weight").val());
	var intro = $.trim($("#intro").val());
	var descr = CKEDITOR.instances.editor1.getData();
	
	$.ajaxFileUpload({
		url:'../../goods/addGood',
		secureuri: false,
		fileElementId:"pic",
		dataType:"json",
		data:{tno:tno, gname:gname,price:price,balance:balance,unit:unit,qperied:qperied,weight:weight,intro:intro,descr:descr},
		success:function(data, stuts) {
			data = parseInt($.trim(data));
			if (data == 1) {
				$("#addGoodsForm")[0].reset();
				$("#showPics").html("");
				CKEDITOR.instances.editor1.setData("");
				alert("商品信息添加成功...");
			} else {
				alert("商品信息添加失败...");
			}
		},
		error:function(data, status, e) {
			alert("商品信息添加失败，请稍后重试...\n" + e);
		}
	});
}
</script>
</body>
</html>